import 'package:dio/dio.dart';
import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:palmf_hid/common/routes/routes.dart';
import 'package:palmf_hid/common/store/user.dart';
import 'package:palmf_hid/common/utils/utils.dart';

import 'login_state.dart';

class LoginLogic extends GetxController {
  final LoginState state = LoginState();
  final Dio dio = Dio();

  LoginLogic();

  final phoneFocusNode = FocusNode();
  final passwordFocusNode = FocusNode();

  final TextEditingController phoneTextEditingController =
      TextEditingController();
  final TextEditingController passwordController = TextEditingController();

  @override
  void onInit() {
    super.onInit();
  }

  Future<void> doLogIn() async {
    var username = phoneTextEditingController.text.toString();
    var password = passwordController.text.toString();
    if (username.isEmpty) {
      MyToastUtil.show("用户不能为空");
    } else if (password.isEmpty) {
      MyToastUtil.show("请填写密码");
    } else if(username=="admin"&&password=="1"){
      UserStore().savePassWord(password);
      UserStore().saveUserName(username);
      Get.offAndToNamed(AppRoutes.MAIN);
    }
  }
}
